﻿using System;

namespace FunctionalCLR.Core.Function {
    public class AssignNode : OperatorNode {

        protected IContext context = null;

        public AssignNode(IContext context)
            : base() {
            this.Value = "=";
            this.Precedence = 0;
            this.context = context;
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NotImplementedException();
        }

        public override object Evaluate() {
            string variableName
                = Left.Value;
            object value = Right.Evaluate().ToString();

            this.context.Assign(variableName, value);

            return value;
        }
    }
}
